package org.csu.webjpetstoreback.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.csu.webjpetstoreback.config.CommonResponse;
import org.csu.webjpetstoreback.mapper.CategoryMapper;
import org.csu.webjpetstoreback.mapper.SequenceMapper;
import org.csu.webjpetstoreback.model.Category;
import org.csu.webjpetstoreback.model.Orders;
import org.csu.webjpetstoreback.model.Sequence;
import org.csu.webjpetstoreback.service.CategoryService;
import org.csu.webjpetstoreback.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SequenceServiceImpl extends ServiceImpl<SequenceMapper, Sequence> implements SequenceService {

    @Autowired
    public SequenceMapper sequenceMapper;


    @Override
    public CommonResponse<Sequence> GetSequence(Sequence sequence) {
        QueryWrapper<Sequence> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", sequence.getName());
        Sequence sequence1 = sequenceMapper.selectOne(queryWrapper);
        if (sequence1 != null) {
            return CommonResponse.BackForSuccess(sequence1);
        } else {
            return CommonResponse.BackForError("不存在当前sequence");
        }
    }
    @Override
    public CommonResponse<Sequence> PutSequence(Sequence sequence) {
        UpdateWrapper<Sequence> UpdateWrapper = new UpdateWrapper<>();
        int result = sequenceMapper.update(sequence,UpdateWrapper);
        if (result ==1){
            return CommonResponse.BackForSuccess("sequence修改成功");
        }else{
            return CommonResponse.BackForError("sequence修改失败");
        }
    }
}
